package com.tang.algorithm.array;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashMap;

/**
 * @author tlm
 * @version 1.0
 * @date 2020/6/5 6:45 下午
 */
public class LeetCode1365 {
    public static void main(String[] args) {
        int[] a = {8,1,2,2,3};
        smallerNumbersThanCurrent(a);
    }
    public static int[] smallerNumbersThanCurrent(int[] nums) {
        int size = nums.length;
        int[] res = new int[size];
        int[] sortNums = Arrays.copyOfRange(nums,0,size);
        HashMap<Integer,Integer> hashMap = new HashMap<>();
        Arrays.sort(sortNums);
        for (int i = 0; i <sortNums.length ; i++) {
            if(!hashMap.containsKey(sortNums[i])) hashMap.put(sortNums[i],i);
        }
        for (int i = 0; i <size ; i++) {
            res[i]=hashMap.get(nums[i]);
        }
        return res;
    }
}
